package com.beiing.tianshuai.tianshuai.dongtai.model;

import com.beiing.tianshuai.tianshuai.dongtai.CallBack;
import com.beiing.tianshuai.tianshuai.entity.DynamicAddRelayCommentBean;
import com.beiing.tianshuai.tianshuai.entity.DynamicAddReplyBean;
import com.beiing.tianshuai.tianshuai.entity.DynamicDeleteBean;
import com.beiing.tianshuai.tianshuai.entity.DynamicPraiseBean;
import com.beiing.tianshuai.tianshuai.entity.DynamicRelayDetailBean;
import com.beiing.tianshuai.tianshuai.entity.FollowBean;
import com.beiing.tianshuai.tianshuai.entity.FollowResultBean;
import com.beiing.tianshuai.tianshuai.network.DataManager;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.annotations.NonNull;
import io.reactivex.observers.DisposableObserver;
import io.reactivex.schedulers.Schedulers;

/**
 * Created by LZQ on 2017/8/24.
 */

public class DynamicRelayDetailModel implements DynamicRelayDetailModelImpl {

    @Override
    public void getRelayDetail(String id, String uid, int type, int page, int num, final CallBack callBack) {
        DisposableObserver<DynamicRelayDetailBean> observer = new DisposableObserver<DynamicRelayDetailBean>() {
            @Override
            public void onNext(@NonNull DynamicRelayDetailBean dynamicRelayDetailBean) {
                callBack.result(dynamicRelayDetailBean);
            }

            @Override
            public void onError(@NonNull Throwable e) {
                callBack.error(e);
            }

            @Override
            public void onComplete() {

            }
        };
        DataManager.getDynamicRelayDetail(id, uid, type, page, num)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);
    }

    @Override
    public void addComment(String rid, String uid, String did, String to_uid, String content, final CallBack callBack) {
        DisposableObserver<DynamicAddRelayCommentBean> observer = new DisposableObserver<DynamicAddRelayCommentBean>() {
            @Override
            public void onNext(@NonNull DynamicAddRelayCommentBean dynamicAddRelayCommentBean) {
                callBack.result(dynamicAddRelayCommentBean);
            }

            @Override
            public void onError(@NonNull Throwable e) {
                callBack.error(e);
            }

            @Override
            public void onComplete() {

            }
        };
        DataManager.getAddRelayCommentResult(rid, uid, did, to_uid, content)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);
    }

    @Override
    public void addReply(String rid, String cid, String form_id, String to_uid, String content, String registration_id, final CallBack callBack) {
        DisposableObserver<DynamicAddReplyBean> observer = new DisposableObserver<DynamicAddReplyBean>() {
            @Override
            public void onNext(@NonNull DynamicAddReplyBean dynamicAddReplyBean) {
                callBack.result(dynamicAddReplyBean);
            }

            @Override
            public void onError(@NonNull Throwable e) {
                callBack.error(e);
            }

            @Override
            public void onComplete() {

            }
        };
        DataManager.getAddRelayReplyResult(rid, cid, form_id, to_uid, content, registration_id)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);
    }

    @Override
    public void addPraise(String uid, String rid, String did, String to_uid, final CallBack callBack) {
        DisposableObserver<DynamicPraiseBean> observer = new DisposableObserver<DynamicPraiseBean>() {
            @Override
            public void onNext(@NonNull DynamicPraiseBean dynamicPraiseBean) {
                callBack.result(dynamicPraiseBean);
            }

            @Override
            public void onError(@NonNull Throwable e) {
                callBack.error(e);
            }

            @Override
            public void onComplete() {

            }
        };
        DataManager.getRelayPraiseResult(uid, rid, did, to_uid)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);
    }

    @Override
    public void deleteComment(String uid, String id, String rid, final CallBack callBack) {
        DisposableObserver<DynamicDeleteBean> observer = new DisposableObserver<DynamicDeleteBean>() {
            @Override
            public void onNext(@NonNull DynamicDeleteBean dynamicDeleteBean) {
                callBack.result(dynamicDeleteBean);
            }

            @Override
            public void onError(@NonNull Throwable e) {
                callBack.error(e);
            }

            @Override
            public void onComplete() {

            }
        };

        DataManager.getRelayCommentDeleteResult(uid, id, rid)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);
    }

    @Override
    public void isFollowed(String fromUid, String toUid, final CallBack callBack) {
        DisposableObserver<FollowBean> observer = new DisposableObserver<FollowBean>() {
            @Override
            public void onNext(@NonNull FollowBean followBean) {
                callBack.result(followBean);
            }

            @Override
            public void onError(@NonNull Throwable e) {
                callBack.error(e);
            }

            @Override
            public void onComplete() {

            }
        };
        DataManager.isFollowed(fromUid, toUid)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);
    }

    @Override
    public void setFollowed(String fromUid, String toUid, final CallBack callBack) {
        DisposableObserver<FollowResultBean> observer = new DisposableObserver<FollowResultBean>() {
            @Override
            public void onNext(@NonNull FollowResultBean followResultBean) {
                callBack.result(followResultBean);
            }

            @Override
            public void onError(@NonNull Throwable e) {
                callBack.error(e);
            }

            @Override
            public void onComplete() {

            }
        };
        DataManager.getFollowResult(fromUid, toUid)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);
    }

    @Override
    public void deleteReply(String uid, String id, final CallBack callBack) {
        DisposableObserver<DynamicDeleteBean> observer = new DisposableObserver<DynamicDeleteBean>() {
            @Override
            public void onNext(@NonNull DynamicDeleteBean dynamicDeleteBean) {
                callBack.result(dynamicDeleteBean);
            }

            @Override
            public void onError(@NonNull Throwable e) {
                callBack.error(e);
            }

            @Override
            public void onComplete() {

            }
        };

        DataManager.getRelayReplyDeleteResult(uid, id)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);
    }

    @Override
    public void praiseComment(String uid, String cid, String did, String to_uid, String rid, final CallBack callBack) {
        DisposableObserver<DynamicPraiseBean> observer = new DisposableObserver<DynamicPraiseBean>() {
            @Override
            public void onNext(@NonNull DynamicPraiseBean praiseBean) {
                callBack.result(praiseBean);
            }

            @Override
            public void onError(@NonNull Throwable e) {
                callBack.error(e);
            }

            @Override
            public void onComplete() {

            }
        };

        DataManager.getRelayCommentPraiseResult(uid, cid, did, to_uid, rid)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);
    }

}
